#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn=1e5+5;
ll T,n,m,l,V,A,sum,t;
long double d[maxn],v[maxn],a[maxn],s[maxn][2],p[maxn];
vector<ll>k[maxn],w[maxn];
priority_queue<pair<ll,ll> >q;
bool b[maxn];
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--)
    {
        cin>>n>>m>>l>>V;
        k->clear();
        A=sum=t=0;
        while(!q.empty())
            q.pop();
        for(ll i=1;i<=n;i++)
        {
            cin>>d[i]>>v[i]>>a[i];
            /*s[i]=(V-v[i]*v[i])/(a[i]*2)+d[i];
            if(a[i]>0&&s[i]<=l)
                sum++;
            if(a[i]<0&&s[i]>=d[i])
                sum++;*/
            if(a[i]==0)
                A++;
        }
        //cout<<222222<<endl;
        for(int i=1;i<=m;i++)
        {
            cin>>p[i];
            for(int j=1;j<=n;j++)
            {
                if(d[j]>p[i])
                    continue;
                long double v1=sqrt(v[j]*v[j]+2*a[j]*(p[i]-d[j]));
                if(v1>V)
                {
                    if(!b[j])
                        b[j]=1,sum++;
                    /*if(a[j]>0&&!b[j])
                        s[j][0]=i,s[j][1]=m;
                    if(a[j]<0)
                        s[j][0]=1,s[j][1]=i;*/
                    k[i].push_back(j);
                    w[j].push_back(i);
                }
            }
        }
        //cout<<1111111111<<endl;
        cout<<sum<<" ";
        if(A==n)
        {
            cout<<m-1;
            continue;
        }
        for(int i=1;i<=m;i++)
            q.push(make_pair(k[i].size(),i));
        while (!q.empty()&&sum)
        {
            ll x=q.top().second;
            //cout<<p[x]<<" ";
            q.pop();
            bool g=0;
            for(int i=0;i<k[x].size();i++)
            {
                if(b[k[x][i]])
                    b[k[x][i]]=0,g=1,sum--;
                if(!sum)
                    break;
            }
            t+=g;
        }
        //out<<t<<endl;
        cout<<m-t<<endl;
    }
    return 0;
}